//
//  SAIndexTabBarVC.m
//  YunFu
//
//  Created by Bager on 2018/9/10.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "SAIndexTabBarVC.h"

#import "SAIndexVC.h"
#import "SAClassifyVC.h"
#import "ZTNavigationViewController.h"

@interface SAIndexTabBarVC ()

@end

@implementation SAIndexTabBarVC

- (void)viewDidLoad
{
    self.tabBar.barTintColor = [UIColor whiteColor];
    self.tabBar.tintColor = kPublicColorRed;
    
    [self loadViewControllers];
    
    [super viewDidLoad];
}

- (void)loadViewControllers
{
    SAIndexVC *index = [[SAIndexVC alloc] init];
    UIImage * normalImageO = [[UIImage imageNamed:@"yf3-botnav5"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * selectImageO = [[UIImage imageNamed:@"yf3-botnav1"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UITabBarItem * firstTabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:normalImageO selectedImage:selectImageO];
    ZTNavigationViewController *firstNav = [self getNavWithVC:index];
    firstNav.tabBarItem = firstTabBarItem;
    
    SAClassifyVC *classify = [[SAClassifyVC alloc] init];
    UIImage * normalImageT = [[UIImage imageNamed:@"yf3-botnav6"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * selectImageT = [[UIImage imageNamed:@"yf3-botnav2"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UITabBarItem * secondTabBarItem = [[UITabBarItem alloc]initWithTitle:@"分类" image:normalImageT selectedImage:selectImageT];
    ZTNavigationViewController *secondNav = [self getNavWithVC:classify];
    secondNav.tabBarItem = secondTabBarItem;
    
    SAIndexVC *rank = [[SAIndexVC alloc] init];
    UIImage * normalImageR = [[UIImage imageNamed:@"yf3-botnav7"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * selectImageR = [[UIImage imageNamed:@"yf3-botnav3"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UITabBarItem * thirdTabBarItem = [[UITabBarItem alloc]initWithTitle:@"购物车" image:normalImageR selectedImage:selectImageR];
    ZTNavigationViewController *thirdNav = [self getNavWithVC:rank];
    thirdNav.tabBarItem = thirdTabBarItem;
    
    SAIndexVC *mine = [[SAIndexVC alloc] init];
    UIImage * normalImageF = [[UIImage imageNamed:@"yf3-botnav8"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * selectImageF = [[UIImage imageNamed:@"yf3-botnav4"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UITabBarItem * forthTabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:normalImageF selectedImage:selectImageF];
    ZTNavigationViewController *forthNav = [self getNavWithVC:mine];
    forthNav.tabBarItem = forthTabBarItem;
    
    NSArray *controllersArray = @[firstNav, secondNav, thirdNav, forthNav];
    [self setViewControllers:controllersArray animated:YES];
    
//    self.selectedIndex = 1;
}

- (ZTNavigationViewController *)getNavWithVC:(UIViewController *)vc
{
    ZTNavigationViewController *nav = [[ZTNavigationViewController alloc] initWithRootViewController:vc];
    nav.navigationBar.translucent = NO;
    nav.navigationBar.barTintColor = kPublicColorRed;
    [nav.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
    temporaryBarButtonItem.title = @"";
    nav.navigationItem.leftBarButtonItem = temporaryBarButtonItem;
    return nav;
}

@end
